<template>
  <div class="feature-config">
    <el-form :model="config" label-width="200px">
      <el-divider content-position="left">聊天功能</el-divider>
      
      <el-form-item label="启用语音输入">
        <el-switch v-model="config.enableVoiceInput" />
        <div class="form-tip">启用后可以使用语音输入功能</div>
      </el-form-item>
      
      <el-form-item label="启用Markdown渲染">
        <el-switch v-model="config.enableMarkdown" />
        <div class="form-tip">启用后AI回复的Markdown格式会被渲染</div>
      </el-form-item>
      
      <el-form-item label="启用代码高亮">
        <el-switch v-model="config.enableCodeHighlight" />
        <div class="form-tip">启用后代码块会进行语法高亮</div>
      </el-form-item>
      
      <el-form-item label="显示推理过程">
        <el-switch v-model="config.enableReasoning" />
        <div class="form-tip">启用后会显示AI的思考过程</div>
      </el-form-item>
      
      <el-form-item label="自动滚动">
        <el-switch v-model="config.autoScroll" />
        <div class="form-tip">新消息自动滚动到底部</div>
      </el-form-item>

      <el-divider content-position="left">数据分析功能</el-divider>
      
      <el-form-item label="启用数据分析">
        <el-switch v-model="config.enableDataAnalysis" />
        <div class="form-tip">启用智能数据分析功能</div>
      </el-form-item>
      
      <el-form-item label="自动生成图表">
        <el-switch v-model="config.autoGenerateCharts" />
        <div class="form-tip">数据分析结果自动生成图表</div>
      </el-form-item>
      
      <el-form-item label="数据刷新频率">
        <el-select v-model="config.dataRefreshInterval" style="width: 200px">
          <el-option label="实时" value="realtime" />
          <el-option label="每分钟" value="1min" />
          <el-option label="每5分钟" value="5min" />
          <el-option label="每小时" value="1hour" />
        </el-select>
        <div class="form-tip">数据分析数据的刷新频率</div>
      </el-form-item>

      <el-divider content-position="left">推荐功能</el-divider>
      
      <el-form-item label="启用智能推荐">
        <el-switch v-model="config.enableRecommendations" />
        <div class="form-tip">启用智能业务推荐功能</div>
      </el-form-item>
      
      <el-form-item label="推荐更新频率">
        <el-select v-model="config.recommendUpdateInterval" style="width: 200px">
          <el-option label="每小时" value="1hour" />
          <el-option label="每天" value="1day" />
          <el-option label="每周" value="1week" />
        </el-select>
        <div class="form-tip">智能推荐的更新频率</div>
      </el-form-item>
      
      <el-form-item label="推荐优先级">
        <el-select v-model="config.recommendPriority" style="width: 200px">
          <el-option label="仅高优先级" value="high" />
          <el-option label="高优先级+普通" value="all" />
        </el-select>
        <div class="form-tip">显示的推荐优先级</div>
      </el-form-item>

      <el-divider content-position="left">ERP助手功能</el-divider>
      
      <el-form-item label="启用ERP助手">
        <el-switch v-model="config.enableERPAssistant" />
        <div class="form-tip">启用ERP智能助手功能</div>
      </el-form-item>
      
      <el-form-item label="自动执行建议">
        <el-switch v-model="config.autoExecuteSuggestions" />
        <div class="form-tip">自动执行低风险的AI建议（谨慎开启）</div>
      </el-form-item>
      
      <el-form-item label="助手响应速度">
        <el-select v-model="config.assistantResponseSpeed" style="width: 200px">
          <el-option label="快速" value="fast" />
          <el-option label="平衡" value="balanced" />
          <el-option label="详细" value="detailed" />
        </el-select>
        <div class="form-tip">ERP助手的响应详细程度</div>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="saveConfig">保存配置</el-button>
        <el-button @click="resetConfig">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'

const config = reactive({
  enableVoiceInput: true,
  enableMarkdown: true,
  enableCodeHighlight: true,
  enableReasoning: true,
  autoScroll: true,
  enableDataAnalysis: true,
  autoGenerateCharts: true,
  dataRefreshInterval: '5min',
  enableRecommendations: true,
  recommendUpdateInterval: '1hour',
  recommendPriority: 'all',
  enableERPAssistant: true,
  autoExecuteSuggestions: false,
  assistantResponseSpeed: 'balanced'
})

const saveConfig = () => {
  localStorage.setItem('ai_feature_config', JSON.stringify(config))
  ElMessage.success('配置已保存')
}

const resetConfig = () => {
  Object.assign(config, {
    enableVoiceInput: true,
    enableMarkdown: true,
    enableCodeHighlight: true,
    enableReasoning: true,
    autoScroll: true,
    enableDataAnalysis: true,
    autoGenerateCharts: true,
    dataRefreshInterval: '5min',
    enableRecommendations: true,
    recommendUpdateInterval: '1hour',
    recommendPriority: 'all',
    enableERPAssistant: true,
    autoExecuteSuggestions: false,
    assistantResponseSpeed: 'balanced'
  })
  ElMessage.info('已重置为默认配置')
}

const loadConfig = () => {
  try {
    const saved = localStorage.getItem('ai_feature_config')
    if (saved) {
      Object.assign(config, JSON.parse(saved))
    }
  } catch (error) {
    console.error('加载配置失败:', error)
  }
}

onMounted(() => {
  loadConfig()
})
</script>

<style scoped lang="scss">
.feature-config {
  padding: 20px;
}

.form-tip {
  font-size: 12px;
  color: #909399;
  margin-top: 4px;
}
</style>
